package com.yayawan.laomigame;

import android.app.Application;


import com.bun.miitmdid.core.JLibrary;
import com.lidroid.jxutils.http.Jxutilsinit;
import com.liulishuo.filedownloader.FileDownloader;
import com.liulishuo.filedownloader.connection.FileDownloadUrlConnection;
import com.yayawan.utils.DeviceUtil;
import com.yayawan.utils.Yayalog;
import com.ycbjie.webviewlib.cache.WebCacheType;
import com.ycbjie.webviewlib.cache.WebViewCacheDelegate;
import com.ycbjie.webviewlib.cache.WebViewCacheWrapper;
import com.ycbjie.webviewlib.utils.X5LogUtils;
import com.ycbjie.webviewlib.utils.X5WebUtils;

import org.jxutils.x;

import java.io.File;

public class App extends Application {


    public static String oaid="2222222";
    @Override
    public void onCreate() {
        super.onCreate();
        X5WebUtils.init(this);
        X5LogUtils.setIsLog(true);
//        X5WebUtils.initCache(this);
//        WebViewCacheDelegate.getInstance().init(new WebViewCacheWrapper.Builder(this));

        FileDownloader.setupOnApplicationOnCreate(this)
                .connectionCreator(new FileDownloadUrlConnection
                        .Creator(new FileDownloadUrlConnection.Configuration()
                        .connectTimeout(15_000) // set connection timeout.
                        .readTimeout(15_000) // set read timeout.
                ))
                .commit();
        //1.创建委托对象
        WebViewCacheDelegate webViewCacheDelegate = WebViewCacheDelegate.getInstance();
        //2.创建调用处理器对象，实现类
        WebViewCacheWrapper.Builder builder = new WebViewCacheWrapper.Builder(this);
        //设置缓存路径，默认getCacheDir，名称CacheWebViewCache
        builder.setCachePath(new File(this.getCacheDir().toString(),"CacheWebView"))
                //设置缓存大小，默认100M
                .setCacheSize(1024*1024*100)
                //设置本地路径
                //.setAssetsDir("yc")
                //设置http请求链接超时，默认20秒
                .setConnectTimeoutSecond(20)
                //设置http请求链接读取超时，默认20秒
                .setReadTimeoutSecond(20)
                //设置缓存为正常模式，默认模式为强制缓存静态资源
                .setCacheType(WebCacheType.FORCE);
        webViewCacheDelegate.init(builder);
        try {
            JLibrary.InitEntry(this);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        x.Ext.init(this);
        if (DeviceUtil.isDebug(this)){
            Yayalog.canlog=true;
        }
        Yayalog.loger("laomi log start");
        Jxutilsinit.init(getApplicationContext());
        //x.Ext.setDebug(BuildConfig.DEBUG); // 是否输出debug日志, 开启debug会影响性能.
    }
}
